﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Host;

namespace CommonComponent.Components
{
    public enum AuthorizationStatus
    {
        /// <summary>
        ///  未授权
        /// </summary>
        Unauthorized,

        /// <summary>
        /// 已授权
        /// </summary>
        Authorized,

        /// <summary>
        /// 已拒绝
        /// </summary>
        Rejected,
    }

    /// <summary>
    /// 权限人
    /// </summary>
    public abstract class AuthorizationUser
    {
        public string AuthorizationUserKey { get; set; }

        public override bool Equals(object obj)
        {
            if (!(obj is AuthorizationUser))
                return false;

            var b_user = obj as AuthorizationUser;

            return b_user.AuthorizationUserKey == AuthorizationUserKey;
        }

        public override int GetHashCode()
        {
            return AuthorizationUserKey.GetHashCode();
        }
    }

    /// <summary>
    /// 授权分组
    /// </summary>
    public abstract class AuthorizationGrouping
    {
        /// <summary>
        /// 权限用户列表
        /// </summary>
        public List<AuthorizationUser> AuthorizationUserList { get; set; }

        /// <summary>
        /// 权限分组列表
        /// </summary>
        public List<AuthorizationGrouping> AuthorizationGroupingList { get; set; }
    }

    /// <summary>
    /// 授权内容项
    /// </summary>
    public abstract class AuthorizationItem
    {
        private AuthorizationStatus _AuthorizationStatus = AuthorizationStatus.Authorized;

        public AuthorizationStatus AuthorizationStatus
        {
            get { return _AuthorizationStatus; }
            set { _AuthorizationStatus = value; }
        }



        /// <summary>
        /// 获取授权状态
        /// </summary>
        /// <returns></returns>
        public AuthorizationStatus GetAuthorizationStatus(AuthorizationUser user)
        {
            return _AuthorizationStatus;
        }
    }



    /// <summary>
    /// 授权管理组件
    /// </summary>
    public class AuthorizationComponents : IComponents
    {
        public List<AuthorizationItem> _AuthorizatioItem = new List<AuthorizationItem>();

        ///// <summary>
        ///// 获取相关授权状态
        ///// 1. 人物比分组优先
        ///// 2. 拒绝比授权优先
        ///// </summary>
        ///// <param name="user"></param>
        ///// <param name="business_key"></param>
        ///// <returns></returns>
        //public AuthorizationStatus GetAuthorizationStatus(AuthorizationUser user, string business_key)
        //{

        //}
    }
}
